unit uEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls, uMap, ExtCtrls;

type
  TfEdit = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    cmdGenMap: TBitBtn;
    SD: TSaveDialog;
    OD: TOpenDialog;
    cmdSaveMap: TBitBtn;
    cmdOpenMap: TBitBtn;
    RG: TRadioGroup;
    RadioGroup1: TRadioGroup;
    TabSheet2: TTabSheet;
    cmdOK: TBitBtn;
    BitBtn5: TBitBtn;
    cmdDel: TBitBtn;
    GroupBox1: TGroupBox;
    sbWater: TSpeedButton;
    sbGround: TSpeedButton;
    sbNone: TSpeedButton;
    GridCB: TCheckBox;
    EditCB: TCheckBox;
    MoveCB: TCheckBox;
    BitBtn7: TBitBtn;
    BitBtn1: TBitBtn;
    procedure cmdOpenMapClick(Sender: TObject);
    procedure cmdSaveMapClick(Sender: TObject);
    procedure cmdGenMapClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure GridCBClick(Sender: TObject);
    procedure EditCBClick(Sender: TObject);
    procedure MoveCBClick(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure cmdDelClick(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fEdit: TfEdit;
  MapSellectID: Integer = 0;
  MapObjectID: Integer = lrNone;
  MapEnemyID: Integer = lrNone;

implementation

uses uSceneGame, uUtils, uAdd;

{$R *.dfm}

procedure TfEdit.cmdOpenMapClick(Sender: TObject);
begin
  OD.FileName := ''; 
  OD.InitialDir := Path;
  if OD.Execute and (OD.FileName <> '') 
    and FileExists(OD.FileName) then
  begin
    Map.LoadFromFile(OD.FileName);
    SceneGame.Render;
  end;
end;

procedure TfEdit.cmdSaveMapClick(Sender: TObject);
begin
  SD.FileName := '';
  SD.InitialDir := Path;
  if SD.Execute and (SD.FileName <> '') then
    Map.SaveToFile(SD.FileName);
end;

procedure TfEdit.cmdGenMapClick(Sender: TObject);
var
  ID: ShortInt;
begin
  ID := RG.ItemIndex; 
  case ID of
    0: Map.Fill(False);
    1: Map.Fill(True);
    2: Map.Generate(7);
    3: Map.Generate(2);
    4: Map.Generate(9);
  end;
  SceneGame.Render;
end;

procedure TfEdit.FormCreate(Sender: TObject);
begin
  PageControl1.TabIndex := 0
end;

procedure TfEdit.GridCBClick(Sender: TObject);
begin
  IsGrid := GridCB.Checked;
  SceneGame.Render;
end;

procedure TfEdit.EditCBClick(Sender: TObject);
begin
  IsEdit := EditCB.Checked;
  sbNone.Enabled := IsEdit;
  sbWater.Enabled := IsEdit;
  sbGround.Enabled := IsEdit;
  GridCB.Enabled := IsEdit;
  MoveCB.Enabled := IsEdit;
  SceneGame.Render;
end;

procedure TfEdit.MoveCBClick(Sender: TObject);
begin
  IsMove := not MoveCB.Checked;
  SceneGame.Render;
end;

procedure TfEdit.cmdDelClick(Sender: TObject);
begin
  MapObjectID := lrNone;
  MapEnemyID := lrNone;
end;

procedure TfEdit.BitBtn5Click(Sender: TObject);
begin
  MapSellectID := lrObj;
  cmdDelClick(Sender);
  fAdd.ShowModal;
end;

procedure TfEdit.BitBtn7Click(Sender: TObject);
begin
  MapSellectID := lrCrt;
  cmdDelClick(Sender);
  fAdd.ShowModal;
end;

procedure TfEdit.FormShow(Sender: TObject);
begin
  Caption := Application.Title;
  Left := 32;
  Top := 32;
end;

procedure TfEdit.BitBtn1Click(Sender: TObject);
begin
  // Add script
  
end;

end.
